exports.MMTopBar = GL2.Node.subclass(
{
    classname: 'MMTopBar',
    
    initialize: function() 
    {
		this._backgroundImage = null;
		this._coinSprite = null;
		this._coinsText = null;
		this._nuggetsText = null;
		this._nuggetSprite = null;
		this._mallName = null;
    },
	
	createView: function() 
	{
		var positionY = 0;
		
		var backgroundPath = this.getBaseResourcePath() + "bar-background.png";
		var coinPath = this.getBaseResourcePath() + "coin.png";
		var nuggetsPath = this.getBaseResourcePath() + "nugget.png";
		
		this._backgroundImage = GLFactory.getSprite([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(positionY)], null, backgroundPath, [TCUtil.getScreenWidth(),TCUtil.getAdjustedHeight(TOP_BAR_BACKGROUND_HEIGHT)]);
		this.addChild(this._backgroundImage);
		
		this.makeTouchSwallower();//DONT CHANGE ITS POSITIOIN
		
		this._coinSprite = GLFactory.getSprite([TCUtil.getAdjustedX(240),TCUtil.getAdjustedY(positionY+28)], null, coinPath, [TCUtil.getAdjustedWidth(50),TCUtil.getAdjustedHeight(20)]);
		this.addChild(this._coinSprite);
		
		this._nuggetSprite = GLFactory.getSprite([TCUtil.getAdjustedX(240),TCUtil.getAdjustedY(positionY+2)], null, nuggetsPath, [TCUtil.getAdjustedWidth(50),TCUtil.getAdjustedHeight(20)]);
		this.addChild(this._nuggetSprite);		
		
		var userCoins = MMGameState.getCurrentUser().getCoins();
		var userNuggets = MMGameState.getCurrentUser().getNuggets();

		this._coinsText = GLFactory.getText([TCUtil.getAdjustedX(290) , TCUtil.getAdjustedY(positionY+38)],100,userCoins,[TCUtil.getAdjustedX(60), TCUtil.getAdjustedY(50)], TCUtil.getAdjustedFontSize(120), GL2.Text.HorizontalAlign.Center, null, GL2.Text.OverflowMode.ReduceFontSize, [0.5, 0.5], null);
		this.addChild(this._coinsText);
		
		this._nuggetsText = GLFactory.getText([TCUtil.getAdjustedX(290) , TCUtil.getAdjustedY(positionY+12)],100,userNuggets,[TCUtil.getAdjustedX(60), TCUtil.getAdjustedY(50)], TCUtil.getAdjustedFontSize(120), GL2.Text.HorizontalAlign.Center, null, GL2.Text.OverflowMode.ReduceFontSize, [0.5, 0.5], null);
		this.addChild(this._nuggetsText);
		
		this._mallName = GLFactory.getText([TCUtil.getAdjustedX(110) , TCUtil.getAdjustedY(positionY+15)],100,"",[TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(50)], TCUtil.getAdjustedFontSize(120), GL2.Text.HorizontalAlign.Center, null, GL2.Text.OverflowMode.ReduceFontSize, [0.0, 0.5], null);
		this.addChild(this._mallName);		
		
		this._avatarCount = GLFactory.getText([TCUtil.getAdjustedX(110) , TCUtil.getAdjustedY(positionY+35)],100,"",[TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(50)], TCUtil.getAdjustedFontSize(120), GL2.Text.HorizontalAlign.Center, null, GL2.Text.OverflowMode.ReduceFontSize, [0.0, 0.5], null);
		this.addChild(this._avatarCount);
		
		if(!DatabaseInterface._isVisitingNeighbor)
		{
			this.showCommunityButton();
		}
	},  
	
	showCommunityButton: function()
	{		
		Social.Common.Service.showCommunityButton([0, 0]);
//		var frame = new UI.ViewGeometry.Rect(60,444,100,35);
//		Social.Common.Service.showBalanceButton(frame, function(error){});
//		
//		
//		
//		
//		Social.Common.People.getUser(500000294,['displayName', 'id'], 	
//		function(error, user)
//		{
//			console.log("zaki:::: User id  is "+user.id);
//			console.log("zaki:::: User id  is "+user.displayName);
//			this._userId = user.id;
//			//var errorCode = error.errorCode;
//			//var errorDesc = error.description;
//		});
//		
//		console.log("zaki:::::: GAConfigurations.getRecordID()"+GAConfigurations._recordId);
//		Social.Common.People.getFriends(500000288, ['displayName','id'], null,  function(error, friends, newResult)
//		{
//			console.log("zaki:::: User id CB  is stingify "+/*JSON.stringify*/(friends.length));
//			
//			console.log("zaki:::: User id cb res  isL "+JSON.stringify(newResult));
//			if(error)
//			{
//				console.log("zaki::: errir "+error.errorCode);
//				console.log("zaki::: errir "+error.description);
//			}
//			else
//			{
//				console.log("zaki::::: FRIEND IS "+JSON.stringify(friends[0]));
//				
//			}
//		});
	},
	
	getNodeHeight : function()
	{
		return TOP_BAR_BACKGROUND_HEIGHT;
	},

	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/controllayer/";
	},
	
	updateTopBar: function () 
	{
		var mallName = '';
		var mallUI = MMGameLayer.getMallUI();
		if(mallUI)
		{
			mallName =  mallUI.getMallObj().getName();
		}
		var userCoins = MMGameState.getCurrentUser().getCoins();
		var userNuggets = MMGameState.getCurrentUser().getNuggets();
		this._coinsText.setText(userCoins);
		this._nuggetsText.setText(userNuggets);
		this._mallName.setText(mallName);
		this._avatarCount.setText(AvatarHandler.getTotalNumberOfAvatars() +" "+Core.Localization.getString("CUSTOMERS"));
	},
	
	makeTouchSwallower: function()
	{
    	this._dissolveTouchesTarget = new GL2.TouchTarget();
    	this._dissolveTouchesTarget.setAnchor(0,0);
		this._dissolveTouchesTarget.setSize([TCUtil.getAdjustedX(480),TCUtil.getAdjustedY(TOP_BAR_BACKGROUND_HEIGHT)]);
        this._dissolveTouchesTarget.setPosition(TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(0));
     
        this._myMessageListener = new Core.MessageListener();
		this._dissolveTouchesTarget.getTouchEmitter().addListener(this._myMessageListener, this.dissolveTouches.bind(this),10); //@ make this 10 go to Constants.
		this._backgroundImage.addChild(this._dissolveTouchesTarget);
	},
	
	dissolveTouches: function()
	{
		return true;
	},
	
	
	destroy: function ()
	{
		if(this._backgroundImage)
		{
			this._backgroundImage.destroy();
			this._backgroundImage = null;
		}
		if(this._coinSprite)
		{
			this._coinSprite.destroy();
			this._coinSprite = null;
		}
		if(this._coinsText)
		{
			this._coinsText.destroy();
			this._coinsText = null;
		}
		if(this._nuggetsText)
		{
			this._nuggetsText.destroy();
			this._nuggetsText = null;
		}
		if(this._nuggetSprite)
		{
			this._nuggetSprite.destroy();
			this._nuggetSprite = null;
		}
		if(this._mallName)
		{
			this._mallName.destroy();
			this._mallName = null;
		}
		if(this._avatarCount)
		{
			this._avatarCount.destroy();
			this._avatarCount = null;
		}
	}
});